package com.exam.bean.paper;

import java.io.Serializable;
import java.util.Date;
import java.util.HashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToMany;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import com.exam.bean.privilege.Employee;


/**
 * 试卷
 *
 */
@Entity
public class Paper implements Serializable{
	
	private static final long serialVersionUID = 4127777045865927878L;

	private String id;//试卷号
	private String name;//试卷名称
	private String term;//学期学年
	private String adapteClass;//适应班级
	private Date start=new Date();//开始有效时间
	private Date end=new Date();//结束有效时间
	private Integer totalscore=0;//总分
	private Boolean visible=true;//是否可见
	private Employee employee;//组卷教师 
	private Set<PaperQuestionType> types=new HashSet<PaperQuestionType>();//该科目的题型
	private Set<Employee> students=new HashSet<Employee>();//考生
	
	public Paper() {}
	
	public Paper(String id) {
		this.id = id;
	}
	
	@Id
	@Column(length=36)
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	
	@Column(length=50,nullable=false)
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	@Column(length=40)
	public String getTerm() {
		return term;
	}
	public void setTerm(String term) {
		this.term = term;
	}
	
	@Column(length=50)
	public String getAdapteClass() {
		return adapteClass;
	}
	public void setAdapteClass(String adapteClass) {
		this.adapteClass = adapteClass;
	}
	
	@Temporal(TemporalType.TIMESTAMP)
	public Date getStart() {
		return start;
	}
	public void setStart(Date start) {
		this.start = start;
	}
	
	@Temporal(TemporalType.TIMESTAMP)
	public Date getEnd() {
		return end;
	}
	public void setEnd(Date end) {
		this.end = end;
	}
	
	@Column(nullable=false)
	public Integer getTotalscore() {
		return totalscore;
	}
	public void setTotalscore(Integer totalscore) {
		this.totalscore = totalscore;
	}
	
	@Column(nullable=false)
	public Boolean getVisible() {
		return visible;
	}
	public void setVisible(Boolean visible) {
		this.visible = visible;
	}

	@ManyToOne(cascade=CascadeType.REFRESH)
	@JoinColumn(name="employeeid")
	public Employee getEmployee() {
		return employee;
	}
	public void setEmployee(Employee employee) {
		this.employee = employee;
	}

	@OneToMany(cascade={CascadeType.REFRESH,CascadeType.REMOVE},mappedBy="paper")
	public Set<PaperQuestionType> getTypes() {
		return types;
	}
	public void setTypes(Set<PaperQuestionType> types) {
		this.types = types;
	}

	@ManyToMany(mappedBy="studentpapers", cascade=CascadeType.REFRESH)
	public Set<Employee> getStudents() {
		return students;
	}
	public void setStudents(Set<Employee> students) {
		this.students = students;
	}

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((id == null) ? 0 : id.hashCode());
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Paper other = (Paper) obj;
		if (id == null) {
			if (other.id != null)
				return false;
		} else if (!id.equals(other.id))
			return false;
		return true;
	}
	
	
}
